from robot.api.deco import keyword
from product.product.interface.info_disclosure.regular_info_disclosure.list_regular_info_disclosure import ListRegularDisclosure
from product.product.interface.login.ProductLogin import ProductLogin
from product.product.product.common.Env import Env
from product.product.product.common.product.env_info import get_product_config
from product.product.util.utils import send_request, product_response_result

class AccountInstitutionControllerKeyword:
    if not Env.cookie:
        = ProductLogin().login_api()

    @keyword(name="业务参数_开户机构_查询")
    def listAll(self, param: dict = None):
        """
        业务参数_开户机构_查询
        :param param:
        :return:
        """
        param = param if param else {}
        request_pa = {
            "url": "/pdms/product/opening/institution/list",
            "request_type": "post",
            "request_data": param
        }
        res,_ = send_request(request_pa, get_product_config())
        return res

    @keyword(name="业务参数_开户机构_新增")
    def insert(self, openingInstitutionCode: str = None, openingInstitutionName: str = 'yyy',
               openingInstitutionAddress="自动化"):
        """
        :param openingInstitutionCode: 开户机构编码
        :param openingInstitutionName: 开户机构名称
        :param dataStatus: 数据状态, 1-有效, 0-无效
        :param openingInstitutionAddress: 开户机构地址
        :return:
        """
        request_pa = {
            "url": "/pdms/product/opening/institution/insert",
            "request_type": "post",
            "request_data": {
                "openingInstitutionAddress": openingInstitutionAddress,
                "openingInstitutionCode": uuid.uuid4().str().split('-')[-1] if not openingInstitutionCode else openingInstitutionCode,
                "openingInstitutionName": openingInstitutionName,
                "customerNo": "999999999"
            }
        }
        res, _ = send_request(request_pa, get_product_config())
        return res

        @keyword(name="业务参数_开户机构_修改")
        def update(self, openingInstitutionCode, code_id, openingInstitutionName: str = "yyy", dataStatus=1, openingInstitutionAddress="自动化"):
            """
            :param openingInstitutionCode: 开户机构编码
            :param code_id: 开户机构编码
            :param openingInstitutionName: 开户机构名称
            :param dataStatus: 数据状态, 1-有效, 0-无效
            :param openingInstitutionAddress: 开户机构地址
            :return:
            """
            request_pa = {
                "url": "/pdms/product/opening/institution/update",
                "request_type": "post",
                "request_data": {
                    "id": code_id,
                    "dataStatus": str(dataStatus),
                    "openingInstitutionAddress": openingInstitutionAddress,
                    "openingInstitutionCode": openingInstitutionCode,
                    "openingInstitutionName": openingInstitutionName,
                    "customerNo": "999999999"
                }
            }
            res, _ = send_request(request_pa, get_product_config())
            return res

        @keyword(name="业务参数_开户机构_删除")
        def delete(self, openingInstitutionCodeID):
            """
            :param openingInstitutionCodeID: 开户机构名称
            :return:
            """
            request_pa = {
                "url": "/pdms/product/opening/institution/delete",
                "request_type": "post",
                "request_data": {
                    "id": openingInstitutionCodeID,
                }
            }
            res, _ = send_request(request_pa, get_product_config())
            return res

        if __name__ == '__main__':
            print(AccountInstitutionControllerKeyword().insert())